/**
 * creater:kunjiang.zhou@dhc.com.cn
 * create time:2017-05-31 17:04:07
 * describe:供应商
 */
APP.controller('SupplierController', ['$scope', '$rootScope', '$state','$stateParams', 'SupplierService',
    function ($scope, $rootScope, $state,$stateParams, SupplierService) {

        /***变量声明***/
        $scope.showName = '';
        $scope.dataList = '';//列表数据
        $scope.acceptType = '';//显示类型,supplier：供应商,paper：纸种,weight：克重,specification:规格,axle:轴序
        $rootScope.onlineAxle = '';//轴序


        /**
         * 初始化函数
         */
        $scope.init = function () {
            $scope.getDataList();
            switch ($scope.acceptType) {
                case 'supplier' :
                    $scope.showName = '供应商';
                    break;
                case 'paper':
                    $scope.showName = '纸种';
                    break;
                case 'weight':
                    $scope.showName= '克重';
                    break;
                case 'specification':
                    $scope.showName = '规格';
                    break;
                case 'axle':
                    $scope.showName = '轴序';
                    break;
            }
            // $httpProvider.defaults.headers.common = { 'token' : $rootScope.token }
        };


        //获取数据列表
        $scope.getDataList = function () {
            console.log($rootScope.token);
            SupplierService.getDataList($scope.acceptType,$rootScope.token)
                .success(function (response) {
                    $scope.typeList = response.data;
                })
        };

        //点击跳转方法
        $scope.clickJump = function (data) {
            // $rootScope.date.($scope.acceptType) = data;
            switch ($scope.acceptType) {
                case 'supplier' :
                    $rootScope.data.supplier = data;
                    break;
                case 'paper':
                    $rootScope.data.paper = data;
                    break;
                case 'weight':
                    $rootScope.data.weight = data;
                    break;
                case 'specification':
                    $rootScope.data.specification = data;
                    break;
                case 'axle':
                    $rootScope.onlineAxle = data;
                    break;
            }
            $rootScope.noRefresh = 1;
            $scope.$ionicGoBack();
        };
        /*
         $scope.init();//如果页面缓存则用此方法初始化
         */
        $scope.$on('$ionicView.beforeEnter', function () {
            $scope.acceptType = $stateParams.type;
            console.log($scope.acceptType);
            $scope.init();
        });
    }
]);

/**
 * creater:kunjiang.zhou@dhc.com.cn
 * create time:2017-05-31 17:04:07
 * describe:供应商
 */
APP.service('SupplierService', ['$http', 'UrlService', function ($http, UrlService) {
    /**
     * 方法
     */
    this.getDataList = function (param,token) {
        var url = 'http://47.94.130.122/api/dictionary/' + param;
        console.log(url);
        return $http.get(url);
    }

}]);
